#
# @lc app=leetcode.cn id=643 lang=python3
#
# [643] 子数组最大平均数 I
#

# @lc code=start
from cmath import inf


class Solution:
    def findMaxAverage(self, nums: List[int], k: int) -> float:
        length = len(nums)
        if k == 1:  # 考虑间隔为1的情况
            max_value = max(nums)
        elif k == length:
            max_value = sum(nums)
        else:
            max_value = temp = sum(nums[:k])
            for i in range(k, len(nums)):
                temp = temp + nums[i] - nums[i-k]
                if max_value < temp:
                    max_value = temp
        return (max_value/k)
# @lc code=end

